var BaseTutorRegStep1 = app.controller('BaseTutorRegStep1', function($http, $scope, $rootScope, $location,$cordovaDevice,$cordovaChat,BaseTutorRegStep1Data) {
	try{
		$rootScope.showf=false;

		$scope.user={};
		var url=SITE_URL+"index.php?app=baseloginapp&callback=JSON_CALLBACK&act=userinfo";
		$http.jsonp(url).success(function(data) {
			$scope.user=data.retval;

			//外部修改值自动加载
			if($rootScope.btrs1_tutor_name!=undefined&&$rootScope.btrs1_tutor_name!=""&&$rootScope.btrs1_tutor_name!=null){
				if ($scope.user.tutor.tutor_name != $rootScope.btrs1_tutor_name) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_tutor_name+"&field=tutor_name"+"&table=xs_tutor";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.tutor.tutor_name=$rootScope.btrs1_tutor_name;
			}

			if($rootScope.btrs1_real_name!=undefined&&$rootScope.btrs1_real_name!=""&&$rootScope.btrs1_real_name!=null){
				if ($scope.user.real_name != $rootScope.btrs1_real_name) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_real_name+"&field=real_name"+"&table=xs_member";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.real_name=$rootScope.btrs1_real_name;
			}

			if($rootScope.btrs1_tel!=undefined&&$rootScope.btrs1_tel!=""&&$rootScope.btrs1_tel!=null){
				if ($scope.user.tutor.tel != $rootScope.btrs1_tel) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_tel+"&field=tel"+"&table=xs_tutor";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.tutor.tel=$rootScope.btrs1_tel;
			}

			if($rootScope.btrs1_city!=undefined&&$rootScope.btrs1_city!=""&&$rootScope.btrs1_city!=null){
				if ($scope.user.city != $rootScope.btrs1_city) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_city+"&field=city"+"&table=xs_member";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.city=$rootScope.btrs1_city;
			}

			if($rootScope.btrs1_trade!=undefined&&$rootScope.btrs1_trade!=""&&$rootScope.btrs1_trade!=null){
				if ($scope.user.trade != $rootScope.btrs1_trade) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_trade+"&field=trade"+"&table=xs_member";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.trade=$rootScope.btrs1_trade;
			}

			if($rootScope.btrs1_organization!=undefined&&$rootScope.btrs1_organization!=""&&$rootScope.btrs1_organization!=null){
				if ($scope.user.organization != $rootScope.btrs1_organization) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_organization+"&field=organization"+"&table=xs_member";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.organization=$rootScope.btrs1_organization;
			}

			if($rootScope.btrs1_position!=undefined&&$rootScope.btrs1_position!=""&&$rootScope.btrs1_position!=null){
				if ($scope.user.position != $rootScope.btrs1_position) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_position+"&field=position"+"&table=xs_member";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.position=$rootScope.btrs1_position;
			}

			if($rootScope.btrs1_email!=undefined&&$rootScope.btrs1_email!=""&&$rootScope.btrs1_email!=null){
				if ($scope.user.email != $rootScope.btrs1_email) {
                    var url = SITE_URL + "index.php?app=baseloginapp&callback=JSON_CALLBACK&act=upfield" +
                        "&fieldvalue=" + $rootScope.btrs1_email+"&field=email"+"&table=xs_member";
                    $http.jsonp(url).success(function (data) {
                    });
                }
				$scope.user.email=$rootScope.btrs1_email;
			}

			$scope.iniconfig();
		});

		//修改真实姓名
		$scope.go_tutor_name=function(){
			if($scope.user.tutor.tutor_name!=undefined&&$scope.user.tutor.tutor_name!=null){
				$rootScope.btrs1_tutor_name=$scope.user.tutor.tutor_name;
			}
			$rootScope.go('tutorname');
		}
		//修改昵称
		$scope.go_real_name=function(){
			if($scope.user.real_name!=undefined&&$scope.user.real_name!=null){
				$rootScope.btrs1_real_name=$scope.user.real_name;
			}
			$rootScope.go('nickname');
		}
		//修改电话
		$scope.go_tel=function(){
			if($scope.user.tutor.tel!=undefined&&$scope.user.tutor.tel!=null){
				$rootScope.btrs1_tel=$scope.user.tutor.tel;
			}
			$rootScope.go('tutortel');
		}
		//修改城市
		$scope.go_city=function(){
			if($scope.user.city!=undefined&&$scope.user.city!=null){
				$rootScope.btrs1_city=$scope.user.city;
			}
			$rootScope.go('tutorcity');
		}
		//修改行业
		$scope.go_trade=function(){
			if($scope.user.trade!=undefined&&$scope.user.trade!=null){
				$rootScope.btrs1_trade=$scope.user.trade;
			}
			$rootScope.go('tutortrade');
		}
		//修改组织
		$scope.go_organization=function(){
			if($scope.user.organization!=undefined&&$scope.user.organization!=null){
				$rootScope.btrs1_organization=$scope.user.organization;
			}
			if($scope.user.position!=undefined&&$scope.user.position!=null){
				$rootScope.btrs1_position=$scope.user.position;
			}
			$rootScope.go('tutorop');
		}
		//修改email
		$scope.go_email=function(){
			if($scope.user.email!=undefined&&$scope.user.email!=null){
				$rootScope.btrs1_email=$scope.user.email;
			}
			$rootScope.go('tutoremail');
		}

		$scope.iniconfig=function(){
			$rootScope.btrs1_tutor_name="";
			$rootScope.btrs1_real_name="";
			$rootScope.btrs1_tel="";
			$rootScope.btrs1_city="";
			$rootScope.btrs1_trade="";
			$rootScope.btrs1_organization="";
			$rootScope.btrs1_position="";
			$rootScope.btrs1_email="";
		}

		$scope.busy=false;
		//关闭本页 清空全局变量
		$scope.finishself=function(){
			$scope.iniconfig();
			$rootScope.back();
		}
		$scope.gostep=function(){
			$scope.iniconfig();
			var tutor_name=$scope.user.tutor.tutor_name;
			var real_name=$scope.user.real_name;
			var tel=$scope.user.tutor.tel;
			var city=$scope.user.city;
			var trade=$scope.user.trade;
			var organization=$scope.user.organization;
			var position=$scope.user.position;
			var email=$scope.user.email;

			if(tutor_name==""||tutor_name==undefined||tutor_name==null){
				showtoast("请填写真实姓名");
				return false;
			}
			if(real_name==""||real_name==undefined||real_name==null){
				showtoast("请填写昵称");
				return false;
			}
			if(tel==""||tel==undefined||tel==null){
				showtoast("请验证手机");
				return false;
			}
			if(city==""||city==undefined||city==null){
				showtoast("请选择城市");
				return false;
			}
			if(trade==""||trade==undefined||trade==null){
				showtoast("请选择行业");
				return false;
			}
			if(organization==""||organization==undefined||organization==null){
				showtoast("请填写就职机构");
				return false;
			}
			if(position==""||position==undefined||position==null){
				showtoast("请填写就职职位");
				return false;
			}
			$rootScope.go("tutorregstep2");
		}
	}
	catch (e) {
		showcatch(e);
	}
});
BaseTutorRegStep1.BaseTutorRegStep1Data=function($q, $http,$stateParams,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
		}else{
			def.resolve(data);
		}
		
		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}